pygrub: Fix command line argument error handling
authorMatthew Daley <mattjd@gmail.com>
Mon, 12 Nov 2012 17:03:21 +0000 (17:03 +0000)
committerMatthew Daley <mattjd@gmail.com>
Mon, 12 Nov 2012 17:03:21 +0000 (17:03 +0000)
pygrub's individual config file parsers do not correctly check the
amount of command line arguments given to them. In addition, the LILO
config parser would report an incorrect message.

Use len() to correctly check the amount of arguments, and fix the LILO
error message.

Signed-off-by: Matthew Daley <mattjd@gmail.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/pygrub/src/ExtLinuxConf.py
tools/pygrub/src/GrubConf.py
tools/pygrub/src/LiloConf.py

index 19776a3c925117ec4bfeee211a86a28eba83ffc1..510099bf59f62da25318b1034738a606e4d3cb0d 100644 (file)
@@ -207,7 +207,7 @@ class ExtLinuxConfigFile(object):
                  }
         
 if __name__ == "__main__":
-    if sys.argv < 2:
+    if len(sys.argv) < 2:
         raise RuntimeError, "Need a configuration file to read"
     g = ExtLinuxConfigFile(sys.argv[1])
     for i in g.images:
index c4f543d1963e8bd6cd692d237fef82031d965990..629951f9410926ff8eb44807cfe0f9de90c8f808 100644 (file)
@@ -454,7 +454,7 @@ class Grub2ConfigFile(_GrubConfigFile):
                 }
         
 if __name__ == "__main__":
-    if sys.argv < 3:
+    if len(sys.argv) < 3:
         raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read"
     if sys.argv[1] == "grub":
         g = GrubConfigFile(sys.argv[2])
index 9858ae26f5f20c143150b1a089630ed57090f631..2cb649f115df4d4886ddb9ac52e38edc3bb5adac 100644 (file)
@@ -169,8 +169,8 @@ class LiloConfigFile(object):
                  }
 
 if __name__ == "__main__":
-    if sys.argv < 2:
-        raise RuntimeError, "Need a grub.conf to read"
+    if len(sys.argv) < 2:
+        raise RuntimeError, "Need a lilo.conf to read"
     g = LiloConfigFile(sys.argv[1])
     for i in g.images:
         print i #, i.title, i.root, i.kernel, i.args, i.initrd